﻿using System;

using System.Collections.Generic;
using System.Text;

namespace Silvermoon.Windows
{
    /// <summary>
    /// Node for <see cref="DblLinkedList"/>.
    /// </summary>
    /// <typeparam name="T">Type of value to contain.</typeparam>
    public class DblLinkedNode<T>
    {
        public DblLinkedNode<T> Previous { get; internal set; }
        public DblLinkedNode<T> Next { get; internal set; }
        public readonly T Value;

        internal DblLinkedNode()
            : base()
        {
        }

        internal DblLinkedNode(T value)
            : base()
        {
            this.Value = value;
        }

        public void Add(DblLinkedNode<T> node)
        {

            node.Next = this.Next;
            node.Previous = this;

            this.Next.Previous = node;
            this.Next = node;
        }

        public void Remove()
        {
            DblLinkedNode<T> prev = Previous;
            this.Previous.Next = Next;
            this.Next.Previous = prev;
        }
    }
}
